package com.wonders.framework.auto.builder.code.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.wonders.framework.auto.builder.code.entity.vo.ColumnInfo;
import com.wonders.framework.auto.builder.code.service.TableService;
import com.wonders.framework.dao.BaseDao;
import com.wonders.framework.entity.vo.Parameter;

/**
 * 表业务实现
 * 
 * @author WuBin
 * 
 */
@Service
public class TableServiceImpl implements TableService {

	@Autowired
	@Qualifier("baseDaoImpl")
	private BaseDao baseDao;

	public List<ColumnInfo> getColumn(String tableName) {
		String sql = "select utc.COLUMN_NAME,utc.DATA_TYPE,utc.DATA_PRECISION,utc.DATA_SCALE,utc.DATA_LENGTH,utc.NULLABLE,ucc.COMMENTS,k.constraint_type from user_tab_columns utc left join user_col_comments ucc on utc.TABLE_NAME = ucc.TABLE_NAME and utc.COLUMN_NAME = ucc.COLUMN_NAME left join (select ucc.COLUMN_NAME, uc.CONSTRAINT_TYPE from user_cons_columns ucc left join user_constraints uc on ucc.CONSTRAINT_NAME = uc.CONSTRAINT_NAME where ucc.TABLE_NAME = 'DEMO' and uc.CONSTRAINT_TYPE = 'P') k on utc.COLUMN_NAME = k.column_name where utc.Table_Name = upper(:tableName) order by utc.COLUMN_ID";
		List<Parameter> args = new ArrayList<Parameter>();
		args.add(new Parameter("tableName", tableName));
		return baseDao.listBySql(sql, args, ColumnInfo.class);
	}

}
